package com.breez.shorturl.util;

import org.iherus.codegen.qrcode.SimpleQrcodeGenerator;
import org.joda.time.DateTime;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

public class QrCodeUtil {

    public static synchronized String createQRCode(String data, String prefix, String code) {
        String path = "";
        String group = new DateTime().toString("yyyy/MM/dd");
        String id = UUID.randomUUID().toString().substring(0, 10).replaceAll("-", "");
        path = prefix + "QR/" + group + "/" + id + code + ".png";

        File file = new File(path);
        if (!file.exists()) {
            file.mkdirs();
        }
        try {
            new SimpleQrcodeGenerator().generate(data).toFile(path);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return path;
    }

    public static void main(String[] args) {
        String group = new DateTime().toString("yyyy/MM/dd");
        System.out.println(group);
    }
}
